package com.milling.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.milling.common.annotation.Log;
import com.milling.common.core.controller.BaseController;
import com.milling.common.core.domain.AjaxResult;
import com.milling.common.enums.BusinessType;
import com.milling.business.domain.WmsNeedleCache;
import com.milling.business.service.IWmsNeedleCacheService;
import com.milling.common.utils.poi.ExcelUtil;
import com.milling.common.core.page.TableDataInfo;

/**
 * 配针缓存区Controller
 *
 * @author X
 * @date 2025-02-04
 */
@RestController
@RequestMapping("/business/needlecache")
public class WmsNeedleCacheController extends BaseController
{
    @Autowired
    private IWmsNeedleCacheService wmsNeedleCacheService;

    /**
     * 查询配针缓存区列表
     */
    @PreAuthorize("@ss.hasPermi('business:needlecache:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsNeedleCache wmsNeedleCache)
    {
        startPage();
        List<WmsNeedleCache> list = wmsNeedleCacheService.selectWmsNeedleCacheList(wmsNeedleCache);
        return getDataTable(list);
    }

    /**
     * 导出配针缓存区列表
     */
    @PreAuthorize("@ss.hasPermi('business:needlecache:export')")
    @Log(title = "配针缓存区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsNeedleCache wmsNeedleCache)
    {
        List<WmsNeedleCache> list = wmsNeedleCacheService.selectWmsNeedleCacheList(wmsNeedleCache);
        ExcelUtil<WmsNeedleCache> util = new ExcelUtil<WmsNeedleCache>(WmsNeedleCache.class);
        util.exportExcel(response, list, "配针缓存区数据");
    }

    /**
     * 获取配针缓存区详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:needlecache:query')")
    @GetMapping(value = "/{needleId}")
    public AjaxResult getInfo(@PathVariable("needleId") Long needleId)
    {
        return success(wmsNeedleCacheService.selectWmsNeedleCacheByNeedleId(needleId));
    }

    /**
     * 新增配针缓存区
     */
    @PreAuthorize("@ss.hasPermi('business:needlecache:add')")
    @Log(title = "配针缓存区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsNeedleCache wmsNeedleCache)
    {
        return toAjax(wmsNeedleCacheService.insertWmsNeedleCache(wmsNeedleCache));
    }

    /**
     * 修改配针缓存区
     */
    @PreAuthorize("@ss.hasPermi('business:needlecache:edit')")
    @Log(title = "配针缓存区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsNeedleCache wmsNeedleCache)
    {
        return toAjax(wmsNeedleCacheService.updateWmsNeedleCache(wmsNeedleCache));
    }

    /**
     * 删除配针缓存区
     */
    @PreAuthorize("@ss.hasPermi('business:needlecache:remove')")
    @Log(title = "配针缓存区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{needleIds}")
    public AjaxResult remove(@PathVariable Long[] needleIds)
    {
        return toAjax(wmsNeedleCacheService.deleteWmsNeedleCacheByNeedleIds(needleIds));
    }
}
